<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-hemisu.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="php,ci,zustmanager,">










<meta name="description" content="今天学生管理系统写到对班级内多用户的信息提交的时候，决定用使用input name里设置数组的形式首先出现了Disallowed Key Characters.（CI框架）查询 得到答案  这和 CI 的字符串处理类设计有关，是这样的，通过get、post方法提交的字符串，CI 都交给 system/core/Input.php这个类去处理，那很多人就问了，看url并没有特殊符号，为什么也报这样的">
<meta name="keywords" content="php,ci,zustmanager">
<meta property="og:type" content="article">
<meta property="og:title" content="post checkbox默认值">
<meta property="og:url" content="http://www.hemisu.com/2015/08/21/15/index.html">
<meta property="og:site_name" content="何米酥`s Blog">
<meta property="og:description" content="今天学生管理系统写到对班级内多用户的信息提交的时候，决定用使用input name里设置数组的形式首先出现了Disallowed Key Characters.（CI框架）查询 得到答案  这和 CI 的字符串处理类设计有关，是这样的，通过get、post方法提交的字符串，CI 都交给 system/core/Input.php这个类去处理，那很多人就问了，看url并没有特殊符号，为什么也报这样的">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2016-09-04T17:35:29.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="post checkbox默认值">
<meta name="twitter:description" content="今天学生管理系统写到对班级内多用户的信息提交的时候，决定用使用input name里设置数组的形式首先出现了Disallowed Key Characters.（CI框架）查询 得到答案  这和 CI 的字符串处理类设计有关，是这样的，通过get、post方法提交的字符串，CI 都交给 system/core/Input.php这个类去处理，那很多人就问了，看url并没有特殊符号，为什么也报这样的">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.hemisu.com/2015/08/21/15/">





  <title>post checkbox默认值 | 何米酥`s Blog</title>
  








  <!-- Hotjar Tracking Code for www.hemisu.com -->
  <script>
      (function(h,o,t,j,a,r){
          h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
          h._hjSettings={hjid:1933736,hjsv:6};
          a=o.getElementsByTagName('head')[0];
          r=o.createElement('script');r.async=1;
          r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
          a.appendChild(r);
      })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
  </script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">何米酥`s Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">EFE</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2015/08/21/15/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">post checkbox默认值</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-08-21T16:39:00+00:00">
                2015-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/默认/" itemprop="url" rel="index">
                    <span itemprop="name">默认</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>今天学生管理系统写到对班级内多用户的信息提交的时候，决定用使用input name里设置数组的形式<br>首先出现了Disallowed Key Characters.（CI框架）<br>查询 得到答案</p>
<blockquote>
<p>这和 CI 的字符串处理类设计有关，是这样的，通过get、post方法提交的字符串，CI 都交给 system/core/Input.php<br>这个类去处理，那很多人就问了，看url并没有特殊符号，为什么也报这样的错误，因为你忽略了一点，cookie 和 session<br>传输的字符串，也是由这个类统一处理的，也就是说，get、post、cookie、session 的数据都是由这个类处理的，问题往往也出现在<br>cookie 和 session 上面，所以网上有很多人提供方法就是，清除一下缓存和 cookie<br>，确实就没问题了，但是隔一段时间就又有问题了，因为新生成的 cookie 里面含有不被匹配通过的字符串，该怎么解决呢？<br>解铃还需系铃人，既然问题出现在 Input.php 这个类上面，就修改他就好，把 _clean_input_keys 方法：</p>
</blockquote>
<pre><code>function _clean_input_keys($str)
{
    if ( ! preg_match(&quot;/^[a-z0-9:_\/-]+$/i&quot;, $str))
    {
        exit(&apos;Disallowed Key Characters.&apos;);
    }
    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
        $str = $this-&gt;uni-&gt;clean_string($str);
    }
    return $str;
}
</code></pre><blockquote>
<p>改为：</p>
</blockquote>
<pre><code>function _clean_input_keys($str)
{
    /*if ( ! preg_match(&quot;/^[a-z0-9:_\/-]+$/i&quot;, $str))
    {
        exit(&apos;Disallowed Key Characters.&apos;);
    }*/
    $config = &amp;get_config(&apos;config&apos;);  
    if (!emptyempty($config[&apos;permitted_uri_chars&apos;]))
    {
        if ( ! preg_match(&quot;/^[&quot;.$config[&apos;permitted_uri_chars&apos;].&quot;]+$/i&quot;, rawurlencode($str)))   
        {   
            exit(&apos;Disallowed Key Characters.&apos;);   
        }  
    }
    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
        $str = $this-&gt;uni-&gt;clean_string($str);
    }
    return $str;
}
</code></pre><p>   然后把 config/config.php 里面的：</p>
<p><code>$config[&#39;permitted_uri_chars&#39;] = &#39;a-z 0-9~%.:_\-&#39;;</code></p>
<p>   改为：</p>
<p><code>$config[&#39;permitted_uri_chars&#39;] = &#39;&#39;;</code><br>然而并没有成功，还是出现Disallowed Key Characters.<br>遂从post的提交页面入手，发现<code>name=&quot;zcmaster[&lt;?=$x?&gt;][&#39;ztyxf&#39;]&quot;</code><br>去掉单引号后正常，数组在html表单里的使用方法竟然与php不同。<br><a href="http://www.jb51.net/article/53929.htm" target="_blank" rel="noopener">php数组索引的Key加引号和不加引号的区别</a><br><a href="http://www.php100.com/cover/php/18.html" target="_blank" rel="noopener">php函数库关于数组</a></p>
<p>第二个问题：<br>当checkbox里的值，勾上了两个可以用name同数组的方法传值<br>问题就在不勾时，$_POST里没有出现checkbox，这样在获取数组的时候就少了一个键。</p>
<p>解决方法：前台加隐藏域 在checkbox的前面再加一个同name的隐藏域<br>问题解决</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/php/" rel="tag"># php</a>
          
            <a href="/tags/ci/" rel="tag"># ci</a>
          
            <a href="/tags/zustmanager/" rel="tag"># zustmanager</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/07/30/11/" rel="next" title="Wish list">
                <i class="fa fa-chevron-left"></i> Wish list
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/09/04/24/" rel="prev" title="2016年9月4日">
                2016年9月4日 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="何米酥">
            
              <p class="site-author-name" itemprop="name">何米酥</p>
              <p class="site-description motion-element" itemprop="description">Just do...</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">202</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">78</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/hemisu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/hemisu" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">何米酥</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
